package com.example.questionsystem.modules.qu.util;

import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;

// FileUtils.java
public class FileUtils {
    
    public static void deleteDirectory(Path directory) throws IOException {
        if (!Files.exists(directory)) return;
        
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory)) {
            for (Path entry : stream) {
                if (Files.isDirectory(entry)) {
                    deleteDirectory(entry);
                } else {
                    Files.delete(entry);
                }
            }
        }
        Files.delete(directory);
    }
}